Skip to content

feat(id): negotiate binary screen patches - #12246

Closed
dezren39 wants to merge 8 commits into
mainfrom
queue/20917-12242-negotiated-screenpatch-v2
Closed

dezren39 wants to merge 8 commits into
mainfrom
queue/20917-12242-negotiated-screenpatch-v2

Conversation

@dezren39

@dezren39 dezren39 commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Stacked on PR #12241, this implements the negotiated transport slice for #12242:

join opts into screen_patches + binary_view_patches
-> supported v2 binary route (versioned ScreenPatch + cursor/revision)
-> malformed frame or patch gap requests viewport resync
otherwise
-> existing v1 text-JSON path

Carries text and bytes through the Rust session adapters and browser WebSocket path. Reconnects retain the matching rendered screen/revision with the resume token. The server restores the participant-bound viewport from the retained baseline before rendering the first resumed view. Compression and bandwidth measurement remain out of scope.

Evidence

The following checks passed on commit 1b575e1, before the latest viewport-restoration change:

  • Rust codec: 7 tests; negotiated binary transport: 1 test.
  • TypeScript: cd pkgs/id/web && bun run test -- src/world-wire.test.ts src/world-contract.test.ts src/world-program.test.ts — 31 tests.
  • Typecheck: cd pkgs/id/web && bun run typecheck.
  • Rust formatting: rustfmt --check --edition 2024 on the Rust source files changed by this PR.
  • git diff --check.

Latest commit 3751be8 adds a Rust integration regression test that reconnects at a non-default viewport and applies a catch-up patch. That test has not yet been run on the latest head; GitHub currently reports no workflow runs or status checks for it.

A package-wide cargo fmt --check reports an existing formatting diff in pkgs/id/benches/world_bench.rs, outside this stacked PR's diff.

Merge Danger

Door: Two-way; the new path is opt-in and v1 text-JSON remains available.

Blast Radius: Medium — negotiated world-session transport across Rust adapters and the browser WebSocket client.

Depends on #12241 landing first. References #12242; it is intentionally not auto-closing because this PR is stacked on a non-default base.


Get evidence
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 21, 2026 13:37
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 12 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c40371d7-8187-436e-b86f-0a4ced15ecb8
Commits

Reviewing files that changed from the base of the PR and between 293706f and 3751be8.

Files ignored due to path filters: 1

  • pkgs/id/Cargo.lock is excluded by !**/*.lock
Files selected for processing: 23

  • doc/2026-11-01_design_id805.md
  • doc/2026-11-21T13-10-15Z_design_screenpatch_binary_negotiation/2026-11-21T13-10-15Z_design_screenpatch_binary_negotiation.md
  • pkgs/id/contract/shell-contract.v1.json
  • pkgs/id/crates/id-cli/src/commands/serve.rs
  • pkgs/id/crates/id-core/Cargo.toml
  • pkgs/id/crates/id-core/src/lib.rs
  • pkgs/id/crates/id-core/src/screen_codec.rs
  • pkgs/id/crates/id-core/src/world_presentation.rs
  • pkgs/id/crates/id-web/src/world_ws.rs
  • pkgs/id/crates/id-worlds/src/shell_contract/tests.rs
  • pkgs/id/crates/id-worlds/src/world_net.rs
  • pkgs/id/crates/id-worlds/src/world_session/mod.rs
  • pkgs/id/crates/id-worlds/src/world_session/resume.rs
  • pkgs/id/crates/id-worlds/src/world_session/session_core.rs
  • pkgs/id/crates/id-worlds/src/world_session/tests.rs
  • pkgs/id/crates/id-worlds/src/world_session/types.rs
  • pkgs/id/crates/id-worlds/src/world_session/view.rs
  • pkgs/id/crates/id-worlds/src/world_ssh.rs
  • pkgs/id/web/src/world-contract.test.ts
  • pkgs/id/web/src/world-program.test.ts
  • pkgs/id/web/src/world-wire.test.ts
  • pkgs/id/web/src/world-wire.ts
  • pkgs/id/web/src/world.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T12:45:21.002146Z 3751be8 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0ca23c9a54

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +227 to +231
let line = match &opts.cwd {
Some(dir) => format!("cd {} && {command}", sh_quote(dir)),
None => command,
};
("sh".to_string(), vec!["-lc".to_string(), line])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Apply the build lock when running locally on the laptop

When fleet shell --build -- cargo test ... runs on the laptop, resolve() selects Target::Local, but this arm ignores opts.build and executes the command directly. Only the remote Target::Laptop arm adds fleet-build-lock. The normal laptop invocation therefore bypasses the fleet-wide build concurrency limit and target-broker setup despite explicitly requesting a build slot. Preserve the lock for local execution when the resolved seat is the laptop.

AGENTS.md reference: AGENTS.md:L30-L32

Useful? React with 👍 / 👎.

Comment on lines +501 to +505
let _ = shortlist::update(file, now, |list| {
list.handed.push(shortlist::Handed {
repo: entry.repo.clone(),
issue: entry.issue,
to: agent.clone(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recheck priority handouts inside the shortlist lock

When two same-host runs reach the priority fallback concurrently, both can load the same handed snapshot and select the same issue before either records its handout. Although shortlist::update locks the write, its closure appends unconditionally without rechecking recently_handed, so both agents receive the same issue despite the two-hour duplicate suppression. Select an eligible candidate and record its handout together inside the locked update.

Useful? React with 👍 / 👎.

Comment thread pkgs/id/web/src/world.ts Resolved
Comment on lines +172 to +176
let path = format!(
"repos/{repo}/issues?state=open&labels={}&per_page=30&sort=created&direction=asc",
encode_label(label)
);
let page = match gh_api(world, &path, route) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Search subsequent pages before declaring priority work unavailable

If the oldest 30 open items for a priority label are held, busy, tracker issues, pull requests, or hands items, the filtering below removes all of them without examining eligible issues on later pages. This can make agent next report no priority work or select lower-priority work indefinitely, and prevents shortlist fill from finding those issues. Both routes in gh_api() issue a single request; the fleet wrapper passes the arguments through unchanged. The installed gh api --help documents --paginate as “Make additional HTTP requests to fetch all pages of results”; no pagination is requested here. Fetch subsequent pages until enough eligible candidates are found or the label's results are exhausted.

Useful? React with 👍 / 👎.

Comment on lines +255 to +256
args.push(if opts.build {
format!("{BUILD_LOCK} {command}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Run the complete remote shell program under the build lock

For the supported single-argument shell-program form, fleet shell --target laptop --build -- 'cd pkgs/id && cargo test' produces ~/tools/fleet-build-lock cd pkgs/id && cargo test. The lock wrapper ends with exec "$@", so it attempts to execute the shell builtin cd as an external program and fails before building. With 'cargo check && cargo test', the second build instead runs after the lock has been released. Invoke a shell underneath the lock with the complete, quoted command string so compound build programs execute correctly and remain locked throughout.

AGENTS.md reference: AGENTS.md:L30-L32

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1b575e1552

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkgs/id/web/src/world.ts Resolved
Base automatically changed from queue/18047-805-phase3 to main November 22, 2026 14:57
dezren39 pushed a commit that referenced this pull request Nov 22, 2026
…ug placement

Reconciles with PR #12246 (the earlier queue implementation of this
slice): adopt its recorded design decision that binary delivery is an
explicit client opt-in — the join frame's binary_view_patches flag —
in addition to the v2 transport negotiation. Both halves are required
before a patch rides a binary frame; a v2 session without the flag
keeps JSON patches (new session test pins this).

Also fixes the WorldClientFrame insertion, which had landed between
WorldClient's doc comment and its derive(Debug).
@dezren39

Copy link
Copy Markdown
Member Author

Closing as superseded — the F12.11 phase 3 work landed through two other PRs, and this branch's implementation should not be merged:

Why not this PR: its codec is a flat envelope that replaces the merged #12241 codec and its golden vectors; its framed transports carry no kind/marker byte and its Rust client cannot consume its own v2 frames; its final head (3751be8) was never test-run (its own body notes this). Its design note's join-opt-in argument was adopted in substance — the merged design gates binary on the join's screen_msgpack flag plus screen_patches plus a byte-capable transport.

Disposition of the review findings on this PR:

Thanks to the author for the early design work — the negotiation question it opened (explicit opt-in vs endpoint-only) is settled in the merged contract's offer-and-observe rule.

@dezren39 dezren39 closed this Nov 22, 2026
dezren39 added a commit that referenced this pull request Nov 22, 2026
A resume token's retained baseline records the viewport that produced
it, but joined() initialized every connection's viewport to None, so
the first resumed view rendered at the program's default size and the
shape-checked consume in send_view always missed for a baseline
retained at a non-default viewport. The resume was silently a full
view every time.

BaselineCache gains a participant-bound, non-consuming peek
(viewport_for); joined() restores the viewport from the retained
baseline before the first send_view consumes the one-shot token.
take_matching still performs the shape-checked consume, and a miss
still falls back to a full view.

The wrong-viewport test is replaced by the regression this behavior
needs: a_resume_token_restores_the_viewport_before_catching_up (the
test PR #12246 wrote but never ran), plus a unit test pinning that
the peek does not consume. Ported from PR #12246 commit 3751be8,
adapted to the post-#12242 session shape.

Refs #12648
dezren39 added a commit that referenced this pull request Nov 22, 2026
The browser never participated in resume: world.ts did not declare
resume_token on the frame type, never adopted the token view frames
carry, never offered one in the join frame, and connect() cleared the
rendered surface and revision on every reconnect — so even a host
willing to send a catch-up patch had nothing to patch against.

Token, surface, and revision now move as one unit: adopted together
from every applied view (JSON and MessagePack paths), offered in the
join frame when the unit is complete, and retained across reconnects.
A same-size resize no longer goes out on a resumable reconnect (it
resets the host's retained baseline); a real viewport change or a
forced resync drops all three together and asks for a full view.
Host view (the read-only HTTP path) clears the token with the
surface, since its renders are not session baselines.

New world-resume.test.ts carries the coverage #12648 names: a
catch-up patch applies after a reconnect with no intervening resize,
and a viewport change drops the unit. Adapted from PR #12246 commit
2b9428d to the screen_msgpack negotiation that landed in #12242.

Refs #12648
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant